import 'package:demo_app_video/commons/router/routes.dart';
import 'package:demo_app_video/widgets/items_data.dart';
import 'package:flutter/material.dart';
import 'package:flutter_adcontent/flutter_adcontent.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:keframe/keframe.dart';

class HistoryPage extends StatefulWidget {
  const HistoryPage({Key? key}) : super(key: key);

  @override
  State<HistoryPage> createState() => _HistoryPageState();
}

class _HistoryPageState extends State<HistoryPage> {
  List<Drama> datas = [];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    get_datas();
  }

  get_datas() async {
    var resultData = await FlutterAdcontent.getDramaHistory(page: -1);
    datas.addAll(resultData);
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xffFFFFFF),
      appBar: AppBar(
        backgroundColor: Color(0xffFFFFFF),
        centerTitle: true,
        scrolledUnderElevation: 0,
        title: Text(
          '历史记录',
          style: TextStyle(fontSize: 16.sp),
        ),
      ),
      body: SizeCacheWidget(
          child: ListView.builder(
        padding: EdgeInsets.only(left: 16.w, right: 16.w, top: 10.h),
        itemBuilder: (BuildContext context, int index) {
          return InkResponse(
            onTap: () {
              Routes()
                  .push(context, Routes.dramaDetails, {'drama': datas[index]});
            },
            child: ItemsDataWidgets(
              img_url: datas[index].coverImage,
              title: datas[index].title,
              sub_title: datas[index].desc,
              all_videos: datas[index].total,
              subscribe: '',
            ),
            highlightColor: Colors.transparent,
            radius: 0.0,
          );
        },
        itemCount: datas.length,
      )),
    );
  }
}
